*	Topic: LAB2 Pt. 13
*	Submitted by : Vishal Verma
*	Date: 2/6/2011
*	Program To generate a sqare wave of 0.5 seconds of ON period and 0.5 seconds of OFF period using timer of 8051.
*	ECEN5613 S2011

			ORG $0000				RESET VECTOR	
			LJMP MAIN
			
			ORG $0100				MAIN PROGRAM
MAIN:
			MOV R4,#0AH				LOAD COUNT OF 10
			MOV R1,#00H				INITIAL COUNT FOR MAIN LOOP
			MOV R2,#80H				INITIAL COUNT FOR ISR LOOP
			MOV DPTR,#70F0H			ADDRESS TO WRITE FOR DEBUG LATCH
			MOV IE,#%00000010		EA=0   ET0 =1
			MOV IP,#%00000010		T0 INTERRUPT HIGHEST PRIORITY
			MOV PSW,#%00000000		SELECT RES BANK 0
			MOV TMOD,#%00000001		TIMER 0 IN MODE 1
			MOV TCON,#%00000000		TF0 = 0 TR0 =0
			MOV TH0,#4CH			LOAD COUNT HIGHER BYTE
			MOV TL0,#00H			LOAD COUNT LOWER BYTE
			SETB IE.7				GLOBAL INTERRUPT ENABLE
			SETB TCON.4				START TIMER
LOOP:		MOV A,R1				GET CURRENT COUNT FOR DBG LAT
			MOVX [DPTR],A			WRITE TO DEBUG LATCH
			INC R1					INCREMENT DBG COUNT
			CJNE R1,#80H,LOOP		COMPARE COUNT TO 80H
			MOV R1,#00H				IF 80, RESET COUNT
			AJMP LOOP				LOOP IN MAIN
			
			ORG $000B				TIMER 0 VECTOR
			SETB P1.6				ISR COUNTER
			LJMP MYISR
			
			ORG $0200				TIME ISR
MYISR:		CLR IE.7				DISABLE GLOBAL INTERRUPTS
			DJNZ R4,NOTDONE			DECREMENT COUNT
			MOV R4,#0AH				RESET COUNT
			CPL P1.7				CHANGE LED STATE
			
NOTDONE:	MOV A,R2				GET ISR DBG COUNT
			MOVX [DPTR],A			WRITE ISR DBG COUNT
			INC R2					INCREMENT ISR DBG COUNT
			CJNE R2,#00H,ENDALL 	COMPARE ISR DBG COUNT TO 00H 
			MOV R2,#80H				RESET ISR DBG COUNT

ENDALL:		MOV TH0,#4CH			TIMER COUNT HIGHER BYTE
			MOV TL0,#00H			TIMER COUNT LOWER BYTE
			SETB IE.7				GLOBAL INTERRUPT ENABLE
			SETB TCON.4				START TIMER
			CLR P1.6				ISR COUNTER
			RETI					RETURN
